import AITalk from '../talkTemplate';
import { GetChangedNextStepMethod } from './defination';
const node = AITalk.getTalks('ivvr');
/**
 * 获取下一步变更的数据
 * @param { Object } preNex 初始的下一步数据 { other: '', noAnswer: ''}
 * @param { Object } curNext 当前的下一步数据  { other: '', noAnswer: ''}
 * @param { Array } preIntention 初始的意图  []
 * @param { Array } curIntention 当前的意图  []
 */
export const getChangedNextStep = (preNext = {}, curNext = {}, preIntention = [], curIntention = []) => {
	let changedNextSteps = [];
	if (!preNext && !curNext && !preIntention && curIntention) {
		return [];
	}

	if (preIntention.length > curIntention.length) {
		// 有删除
		console.log('有删除!', changedNextSteps);
		preIntention.map((item, index) => {
			if (curIntention[index]) {
				if (item.nextStepsAnswer !== curIntention[index].nextStepsAnswer) {
					changedNextSteps.push({
						text: `回答分支${index + 1}`,
						type: `ivvr${index + 1}`,
						previous: item.nextStepsAnswer,
						current: curIntention[index].nextStepsAnswer
					});
				}
			} else {
				changedNextSteps.splice(0, 0, {
					text: `回答分支${index + 1}`,
					type: `ivvr${index + 1}`,
					previous: item.nextStepsAnswer,
					current: null
				});
			}
		});
	} else {
		// 有新增
		curIntention.map((item, index) => {
			if (preIntention[index]) {
				if (item.nextStepsAnswer !== preIntention[index].nextStepsAnswer) {
					changedNextSteps.push({
						text: `回答分支${index + 1}`,
						type: `ivvr${index + 1}`,
						previous: preIntention[index].nextStepsAnswer,
						current: item.nextStepsAnswer
					});
				}
			} else {
				changedNextSteps.push({
					text: `回答分支${index + 1}`,
					type: `ivvr${index + 1}`,
					previous: null,
					current: item.nextStepsAnswer
				});
			}
		});
	}

	if (preNext['other'] !== curNext['other']) {
		changedNextSteps.push({
			text: '其他回答',
			type: node.errorRemind.type,
			previous: preNext['other'],
			current: curNext['other']
		});
	}
	if (preNext['noAnswer'] !== curNext['noAnswer']) {
		changedNextSteps.push({
			text: '不回答',
			type: node.emptyErrorRemind.type,
			previous: preNext['noAnswer'],
			current: curNext['noAnswer']
		});
	}

	return changedNextSteps;
};
GetChangedNextStepMethod['ivvr'] = getChangedNextStep;
